export function getCartesian2dGraphOption (data, colors, config) {
  let series = []
  let label = []
  colors = colors || ['rgba(255, 86, 142, 0.6)', 'rgba(255, 175, 49, 0.6)', 'rgba(12, 246, 185, 0.6)', 'rgba(128, 110, 250, 0.6)']
  const opt = Object.assign({
    title: '',
    unit: '',
    label: [],
    rotate: 0,
    xAxisFontSize: 14,
    yAxisFontSize: 14,
    xMax: 100,
    yMax: 100,
    formatLabel: false
  }, config)
  data.forEach(item => {
    series.push({
      type: 'graph',
      layout: 'none',
      coordinateSystem: 'cartesian2d',
      data: item.list
    })
  })
  let top = opt.unit ? 50 : 30
  if (opt.label.length) {
    label = opt.label
  } else {
    for (let i = 0; i < data[0].list.length; i++) {
      let item = data[0].list[i]
      label.push(item.name)
    }
  }
  return {
    color: colors,
    title: { show: !!opt.title, text: opt.title, icon: 'circle', left: 'center', textStyle: { color: '#989898', fontSize: 16 } },
    grid: { left: 12, top: top, bottom: 20, right: 10, containLabel: true },
    yAxis: {
      name: opt.unit,
      nameTextStyle: { color: '#7F7FB5', fontSize: 12 },
      nameGap: 20,
      max: opt.yMax,
      axisLabel: { show: true, textStyle: { color: '#7F7FB5', fontSize: opt.yAxisFontSize } },
      axisLine: { show: true, lineStyle: { color: '#7F7FB5' } },
      axisTick: { show: false },
      splitArea: { show: false },
      splitLine: { show: true, lineStyle: { color: 'rgba(144, 144, 144, 0.2)', type: 'dashed' } }
    },
    xAxis: [{
      min: 0,
      show: false,
      max: opt.xMax
    }, {
      position: 'bottom',
      min: 0,
      type: 'category',
      boundaryGap: false,
      nameTextStyle: { color: '#FFF', fontSize: 12 },
      axisLabel: {
        margin: 15,
        textStyle: {
          color: '#7F7FB5',
          fontSize: opt.xAxisFontSize
        },
        interval: 0,
        rotate: opt.rotate,
        formatter: !!opt.formatLabel && typeof opt.formatLabel === 'function' ? opt.formatLabel : '{value}'
      },
      axisLine: { show: true, lineStyle: { color: '#7F7FB5' } },
      splitLine: { show: true, lineStyle: { color: 'rgba(144, 144, 144, 0.2)', type: 'dashed' } },
      axisTick: { show: false },
      data: label
    }],
    series: series
  }
}
